package com.health.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.health.common.PageBean;
import com.health.common.PageQueryDTO;
import com.health.mapper.CheckitemMapper;
import com.health.pojo.Checkitem;
import com.health.service.CheckitemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 检擦项目服务层实现
 * @author zhangzhen
 * @version 1.0
 * @date 2025/1/17 1:10
 */
@Slf4j
@Service
public class CheckitemServiceImpl implements CheckitemService {
    @Autowired
    private CheckitemMapper checkitemMapper;
    @Override
    public PageBean<Checkitem> findPage(PageQueryDTO pg) {
        PageHelper.startPage(pg.getCurrentPage(),pg.getPageSize());
        List<Checkitem> list = checkitemMapper.findPage(pg);
        Page<Checkitem> p= (Page<Checkitem>) list;
        return new PageBean<>(p.getTotal(),p.getResult());
    }

    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void add(Checkitem checkitem) {
        checkitemMapper.add(checkitem);
    }

    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void deleteById(Integer id) {
        checkitemMapper.deleteById(id);
    }

    @Override
    public Checkitem findById(Integer id) {
       Checkitem checkitem= checkitemMapper.findById(id);
       return checkitem;
    }

    @Override
    public void update(Checkitem checkitem) {
        checkitemMapper.update(checkitem);
    }

    @Override
    public List<Checkitem> findAll() {
        return  checkitemMapper.findAll();
    }
}